Component({
    properties: {
        preload: {
            type: Boolean,
            value: !1
        }
    },
    data: {
        config: {}
    },
    ready: function() {
        var t = this;
        if (this.renderType = "", this.data.preload) {
            var n = this.selectComponent("#poster");
            this.downloadStatus = "doing", n.downloadResource(this.data.config.images).then(function() {
                t.downloadStatus = "success", t.trigger("downloadSuccess");
            }).catch(function(n) {
                t.downloadStatus = "fail", t.trigger("downloadFail", n);
            });
        }
    },
    methods: {
        trigger: function(t, n) {
            this.listener && "function" == typeof this.listener[t] && this.listener[t](n);
        },
        once: function(t, n) {
            void 0 === this.listener && (this.listener = {}), this.listener[t] = n;
        },
        downloadResource: function() {
            var t = this;
            return new Promise(function(n, e) {
                var o = t.selectComponent("#poster");
                t.downloadStatus && "fail" !== t.downloadStatus ? "success" === t.downloadStatus ? t.renderType !== t.data.config.renderType ? (t.renderType = t.data.config.renderType, 
                o.downloadResource(t.data.config.images).then(function() {
                    t.downloadStatus = "success", n();
                }).catch(function(t) {
                    return e(t);
                })) : n() : (t.once("downloadSuccess", function() {
                    return n();
                }), t.once("downloadFail", function(t) {
                    return e(t);
                })) : o.downloadResource(t.data.config.images).then(function() {
                    t.downloadStatus = "success", n();
                }).catch(function(t) {
                    return e(t);
                });
            });
        },
        onCreate: function(t) {
            var n = this;
            this.setData({
                config: t
            }, function() {
                return !n.data.config.hideLoading && wx.showLoading({
                    mask: !0,
                    title: "生成中"
                }), n.downloadResource().then(function() {
                    !n.data.config.hideLoading && wx.hideLoading(), n.selectComponent("#poster").create(n.data.config);
                }).catch(function(t) {
                    !n.data.config.hideLoading && wx.hideLoading(), wx.showToast({
                        icon: "none",
                        title: t.errMsg || "生成失败"
                    }), console.error(t), n.triggerEvent("fail", t);
                });
            });
        },
        onCreateSuccess: function(t) {
            var n = t.detail;
            this.triggerEvent("success", n);
        },
        onCreateFail: function(t) {
            console.error(t), this.triggerEvent("fail", t);
        }
    }
});